home *** CD-ROM | disk | FTP | other *** search
/ Family Forum 262 / SOMC Family Forum 262.iso / Xtras / Animation Wizard.dir / 00011_Bullets.ls < prev    next >
Encoding:
Text File  |  1997-05-10  |  15.2 KB  |  401 lines

  1. property ioFieldList, iFieldFocus, ioFIeldFocus, iCurrentMotionStyleIndex, iCurrentVisualStyleIndex, ikMotionInstant, ikMotionWipe, ikMotionRoll, ikMotionRipple, iFirstTime, iSaveSeconds, iSaveFPS, iSaveDelayEnter, iSaveDelayHold, iSaveMark, iSaveAnimateTitle
  2.  
  3. on birth me
  4.   global goBulletsText, goSeconds, goFPS, goDelayEnter, goDelayHold
  5.   set ioFieldList to [goBulletsText, goSeconds, goFPS, goDelayEnter, goDelayHold]
  6.   set ikMotionInstant to 1
  7.   set ikMotionWipe to 2
  8.   set ikMotionRoll to 3
  9.   set ikMotionRipple to 4
  10.   set iCurrentMotionStyleIndex to ikMotionInstant
  11.   set iCurrentVisualStyleIndex to 1
  12.   set iFieldFocus to 1
  13.   set iFirstTime to 1
  14.   return me
  15. end
  16.  
  17. on mInit me
  18.   global goSeconds, goFPS, goDelayEnter, goDelayHold, goBullets, goMarkFrame, goAnimateTitle, goVisualStyles, goMotionStyles, goScoreMgr
  19.   mInit(goMarkFrame, 4)
  20.   mInit(goAnimateTitle, 22)
  21.   if iFirstTime then
  22.     mSetValue(goSeconds, 5)
  23.     mSetValue(goFPS, 5)
  24.     mSetValue(goDelayEnter, 5)
  25.     mSetValue(goDelayHold, 5)
  26.     mSetValue(goMarkFrame, 1)
  27.     mSetValue(goAnimateTitle, 1)
  28.     set iFirstTime to 0
  29.   else
  30.     mSetValue(goSeconds, iSaveSeconds)
  31.     mSetValue(goFPS, iSaveFPS)
  32.     mSetValue(goDelayEnter, iSaveDelayEnter)
  33.     mSetValue(goDelayHold, iSaveDelayHold)
  34.     mSetValue(goMarkFrame, iSaveMark)
  35.     mSetValue(goAnimateTitle, iSaveAnimateTitle)
  36.   end if
  37.   set ioFIeldFocus to getAt(ioFieldList, iFieldFocus)
  38.   set goMotionStyles to 0
  39.   set goMotionStyles to birth(script "RadioButton", 26, 4, 0, iCurrentMotionStyleIndex)
  40.   if the machineType < 256 then
  41.     mInit(goVisualStyles, the number of member "BulletsVisualStylesMac", iCurrentVisualStyleIndex, 8, 19)
  42.   else
  43.     mInit(goVisualStyles, the number of member "BulletsVisualStylesPC", iCurrentVisualStyleIndex, 8, 19)
  44.   end if
  45.   set the keyDownScript to "mCheckKey(goBullets)"
  46. end
  47.  
  48. on mSetFieldFocus me, oWhom
  49.   set where to getOne(ioFieldList, oWhom)
  50.   if where = 0 then
  51.     alert("Internal error - mSetFieldFocus could not find object")
  52.     return 
  53.   end if
  54.   set iFieldFocus to where
  55.   set ioFIeldFocus to getAt(ioFieldList, iFieldFocus)
  56. end
  57.  
  58. on mCheckKey me
  59.   if the key = TAB then
  60.     set iFieldFocus to IncrMod(iFieldFocus, count(ioFieldList))
  61.     set ioFIeldFocus to getAt(ioFieldList, iFieldFocus)
  62.     pass()
  63.   else
  64.     if iFieldFocus = 1 then
  65.       pass()
  66.     else
  67.       if (offset(the key, "0123456789") > 0) or (the key = BACKSPACE) then
  68.         pass()
  69.       else
  70.         dontPassEvent()
  71.       end if
  72.     end if
  73.   end if
  74. end
  75.  
  76. on mSetNewMotionStyle me, theNewStyleIndex
  77.   set iCurrentMotionStyleIndex to theNewStyleIndex
  78. end
  79.  
  80. on mSetNewVisualStyle me, theNewStyleIndex
  81.   set iCurrentVisualStyleIndex to theNewStyleIndex
  82. end
  83.  
  84. on mValidate me
  85.   set lastFieldOKFlag to mValidate(ioFIeldFocus)
  86.   return lastFieldOKFlag
  87. end
  88.  
  89. on mParseField me, theTextToParse, theHeaderFont, theHeaderSize, theBodyFont, theBodySize
  90.   global gCastNumTextAsBitmap
  91.   set castNumHeader to mModifyRichTextCM(goCastMgr, line 1 of theTextToParse, theHeaderFont, theHeaderSize)
  92.   if castNumHeader = 0 then
  93.     return 0
  94.   end if
  95.   set castNumHeaderTarget to mFindFreeCastRun(goCastMgr, 1, 1)
  96.   copyToClipBoard(member castNumHeader)
  97.   tell the stage
  98.     pasteClipBoardInto(member castNumHeaderTarget)
  99.     set the name of member castNumHeaderTarget to "RichText" && string(the ticks)
  100.   end tell
  101.   set castNumList to [castNumHeaderTarget]
  102.   set maxWidth to 0
  103.   set the picture of member gCastNumTextAsBitmap to the picture of member castNumHeader
  104.   set maxWidth to the width of member gCastNumTextAsBitmap
  105.   set heightHeader to the height of member castNumHeader / the number of lines in the text of member castNumHeader
  106.   repeat with thisLine = 2 to the number of lines in theTextToParse
  107.     set thisBodyLine to line thisLine of theTextToParse
  108.     set castNumBody to mModifyRichTextCM(goCastMgr, thisBodyLine, theBodyFont, theBodySize)
  109.     if castNumBody = 0 then
  110.       return 0
  111.     end if
  112.     set castNumBodyTarget to mFindFreeCastRun(goCastMgr, 1, 1)
  113.     copyToClipBoard(member castNumBody)
  114.     tell the stage
  115.       pasteClipBoardInto(member castNumBodyTarget)
  116.       set the name of member castNumBodyTarget to "RichText" && string(the ticks)
  117.     end tell
  118.     add(castNumList, castNumBodyTarget)
  119.     set the picture of member gCastNumTextAsBitmap to the picture of member castNumBody
  120.     set thisWidth to the width of member gCastNumTextAsBitmap
  121.     if thisWidth > maxWidth then
  122.       set maxWidth to thisWidth
  123.     end if
  124.   end repeat
  125.   set heightBody to the height of member castNumBody / the number of lines in the text of member castNumBody
  126.   set maxHeight to max(heightHeader, heightBody)
  127.   add(castNumList, maxHeight)
  128.   add(castNumList, maxWidth)
  129.   return castNumList
  130. end
  131.  
  132. on mCreate me
  133.   global goMarkFrame, goMotionStyles, goVisualStyles, goScoreMgr, goCastMgr, gDevelopmentFlag, gCastNumTextAsBitmap, goAnimateTitle, goPlatform
  134.   if not mValidate(me) then
  135.     return 
  136.   end if
  137.   if the last char in field "BulletsText" = RETURN then
  138.     delete char -30000 of field "BulletsText"
  139.   end if
  140.   if field "BulletsText" = EMPTY then
  141.     alert("Please enter some text for the Bullet.")
  142.     return 
  143.   end if
  144.   if the number of lines in field "BulletsText" < 2 then
  145.     alert("Bullets requires at least two lines of text, one header and any number of bullets.")
  146.     return 
  147.   end if
  148.   tell the stage
  149.     set theStageFrame to the frame
  150.   end tell
  151.   set castNumVisualStyle to mGetCastNum(goVisualStyles, iCurrentVisualStyleIndex)
  152.   set theVisualStyleName to the name of cast castNumVisualStyle
  153.   set theHeaderFont to word 2 of theVisualStyleName
  154.   set theHeaderSize to word 3 of theVisualStyleName
  155.   set theBodyFont to word 4 of theVisualStyleName
  156.   set theBodySize to word 5 of theVisualStyleName
  157.   set theSeconds to integer(field "Seconds")
  158.   set animateTitleFlag to mGetValue(goAnimateTitle)
  159.   set fps to integer(field "FPS")
  160.   set nFrames to integer(theSeconds * fps)
  161.   set delayEnter to integer(field "DelayEnter")
  162.   set delayHold to integer(field "DelayHold")
  163.   set markFirst to mGetValue(goMarkFrame)
  164.   set theForeColor to 255
  165.   set theBackColor to 0
  166.   if the machineType < 256 then
  167.     set charsToPrepend to "ΓÇó  "
  168.   else
  169.     set charsToPrepend to "-  "
  170.   end if
  171.   set nSourceLines to the number of lines in field "BulletsText"
  172.   set theSourceText to field "BulletsText"
  173.   repeat with thisLine = 2 to nSourceLines
  174.     put charsToPrepend before line thisLine of theSourceText
  175.   end repeat
  176.   set bulletsList to mParseField(me, theSourceText, theHeaderFont, theHeaderSize, theBodyFont, theBodySize)
  177.   if bulletsList = 0 then
  178.     return 
  179.   end if
  180.   set widthIndex to count(bulletsList)
  181.   set maxWidth to getAt(bulletsList, widthIndex)
  182.   deleteAt(bulletsList, widthIndex)
  183.   set heightIndex to count(bulletsList)
  184.   set maxHeight to getAt(bulletsList, heightIndex)
  185.   deleteAt(bulletsList, heightIndex)
  186.   set theStageWidth to mGetStageWidth(goScoreMgr)
  187.   set leftEdge to integer((theStageWidth / 2) - (maxWidth / 2))
  188.   set theStageHeight to mGetStageHeight(goScoreMgr)
  189.   set nextV to integer((theStageHeight / 2) - (nSourceLines * value(maxHeight) / 2))
  190.   set locVList to []
  191.   repeat with thisLine = 1 to nSourceLines
  192.     add(locVList, nextV)
  193.     set nextV to nextV + value(maxHeight)
  194.   end repeat
  195.   case iCurrentMotionStyleIndex of
  196.     ikMotionInstant:
  197.       set thisTransition to "Dissolve, Pixels Fast"
  198.       if animateTitleFlag then
  199.         set nFrames to 1
  200.       else
  201.         set nFrames to 2
  202.       end if
  203.     ikMotionWipe:
  204.       set thisTransition to "Wipe Down"
  205.       if animateTitleFlag then
  206.         set nFrames to 1
  207.       else
  208.         set nFrames to 2
  209.       end if
  210.     ikMotionRoll:
  211.       set thisTransition to 0
  212.       set nFramesPerTransition to (theSeconds * fps) + 1
  213.       if animateTitleFlag then
  214.         set nFrames to nFramesPerTransition * nSourceLines
  215.       else
  216.         set nFrames to (nFramesPerTransition * (nSourceLines - 1)) + 1
  217.       end if
  218.     ikMotionRipple:
  219.       set thisTransition to 0
  220.       set nAnimationFrames to theSeconds * fps
  221.       if animateTitleFlag then
  222.         set nFrames to nAnimationFrames + 1
  223.       else
  224.         set nFrames to nAnimationFrames + 2
  225.       end if
  226.   end case
  227.   if not mInit(goScoreMgr, nFrames, nSourceLines) then
  228.     return 
  229.   end if
  230.   set chList to []
  231.   repeat with i = 1 to nSourceLines
  232.     set chNext to mGetNextSelectedChannel(goScoreMgr)
  233.     add(chList, chNext)
  234.   end repeat
  235.   set theFrameNum to mGetStartFrame(goScoreMgr)
  236.   set frameList to []
  237.   repeat with i = theFrameNum to theFrameNum + nFrames - 1
  238.     add(frameList, [i])
  239.   end repeat
  240.   if markFirst then
  241.     set theLabel to "AW.Bullet." & word 1 of the text of field "BulletsText" & " " & mGetGeneratedScoreSelection(goScoreMgr)
  242.     set firstFrame to getAt(frameList, 1)
  243.     add(firstFrame, [#label, theLabel])
  244.     setAt(frameList, 1, firstFrame)
  245.   end if
  246.   set relFrameCount to 1
  247.   if not animateTitleFlag then
  248.     if thisTransition <> 0 then
  249.       set currentFrame to getAt(frameList, relFrameCount)
  250.       add(currentFrame, [#transition, thisTransition])
  251.       setAt(frameList, relFrameCount, currentFrame)
  252.     end if
  253.     set chHeader to getAt(chList, 1)
  254.     set castNumHeader to getAt(bulletsList, 1)
  255.     set locVHeader to getAt(locVList, 1)
  256.     set currentFrame to getAt(frameList, relFrameCount)
  257.     add(currentFrame, [#tempo, -delayEnter])
  258.     add(currentFrame, [#sprite, chHeader, castNumHeader, theForeColor, theBackColor, leftEdge, locVHeader, 0, 0])
  259.     setAt(frameList, relFrameCount, currentFrame)
  260.     set theFrameNum to theFrameNum + 1
  261.     set relFrameCount to relFrameCount + 1
  262.   end if
  263.   if (iCurrentMotionStyleIndex = ikMotionInstant) or (iCurrentMotionStyleIndex = ikMotionWipe) then
  264.     set currentFrame to getAt(frameList, relFrameCount)
  265.     add(currentFrame, [#transition, thisTransition])
  266.     repeat with thisItem = 1 to nSourceLines
  267.       set chItem to getAt(chList, thisItem)
  268.       set castNumItem to getAt(bulletsList, thisItem)
  269.       set locVItem to getAt(locVList, thisItem)
  270.       add(currentFrame, [#tempo, -delayHold])
  271.       add(currentFrame, [#sprite, chItem, castNumItem, theForeColor, theBackColor, leftEdge, locVItem, 0, 0])
  272.       setAt(frameList, relFrameCount, currentFrame)
  273.     end repeat
  274.     set theFrameNum to theFrameNum + 1
  275.     set relFrameCount to relFrameCount + 1
  276.   else
  277.     set theStageRight to mGetStageRight(goScoreMgr)
  278.     set offStagePos to theStageRight + 10
  279.     if animateTitleFlag then
  280.       set startItem to 1
  281.       set locHList to []
  282.     else
  283.       set startItem to 2
  284.       set locHList to [leftEdge]
  285.     end if
  286.     if iCurrentMotionStyleIndex = ikMotionRoll then
  287.       repeat with i = startItem to nSourceLines
  288.         add(locHList, offStagePos)
  289.       end repeat
  290.       set nFramesPerAnimation to theSeconds * fps
  291.       set hInc to float(leftEdge - offStagePos) / float(nFramesPerAnimation)
  292.       repeat with thisBullet = startItem to nSourceLines
  293.         set thisH to getAt(locHList, thisBullet)
  294.         set currentFrame to getAt(frameList, relFrameCount)
  295.         add(currentFrame, [#tempo, fps])
  296.         setAt(frameList, relFrameCount, currentFrame)
  297.         repeat with i = 1 to nFramesPerAnimation
  298.           set thisH to integer(thisH + hInc)
  299.           if thisH < leftEdge then
  300.             set thisH to leftEdge
  301.           end if
  302.           setAt(locHList, thisBullet, thisH)
  303.           set currentFrame to getAt(frameList, relFrameCount)
  304.           repeat with thisItem = 1 to nSourceLines
  305.             set chItem to getAt(chList, thisItem)
  306.             set castNumItem to getAt(bulletsList, thisItem)
  307.             set locVItem to getAt(locVList, thisItem)
  308.             set locHItem to getAt(locHList, thisItem)
  309.             add(currentFrame, [#sprite, chItem, castNumItem, theForeColor, theBackColor, locHItem, locVItem, 0, 0])
  310.           end repeat
  311.           setAt(frameList, relFrameCount, currentFrame)
  312.           set theFrameNum to theFrameNum + 1
  313.           set relFrameCount to relFrameCount + 1
  314.         end repeat
  315.         set currentFrame to getAt(frameList, relFrameCount)
  316.         add(currentFrame, [#tempo, -delayHold])
  317.         repeat with thisItem = 1 to nSourceLines
  318.           set chItem to getAt(chList, thisItem)
  319.           set castNumItem to getAt(bulletsList, thisItem)
  320.           set locVItem to getAt(locVList, thisItem)
  321.           set locHItem to getAt(locHList, thisItem)
  322.           add(currentFrame, [#sprite, chItem, castNumItem, theForeColor, theBackColor, locHItem, locVItem, 0, 0])
  323.         end repeat
  324.         setAt(frameList, relFrameCount, currentFrame)
  325.         set theFrameNum to theFrameNum + 1
  326.         set relFrameCount to relFrameCount + 1
  327.       end repeat
  328.     else
  329.       set nBulletsToMove to nSourceLines - startItem + 1
  330.       set pctOverlap to 0.25
  331.       set hDistance1Line to float(leftEdge - offStagePos)
  332.       set effectiveNLines to 1.0 + (pctOverlap * nBulletsToMove)
  333.       set totalHDistance to effectiveNLines * hDistance1Line
  334.       set hInc to totalHDistance / float(nAnimationFrames)
  335.       set staggerOffset to -1 * integer(hDistance1Line * pctOverlap)
  336.       set multiplier to 0
  337.       repeat with thisItem = startItem to nSourceLines
  338.         set startingPos to offStagePos + (multiplier * staggerOffset)
  339.         add(locHList, startingPos)
  340.         set multiplier to multiplier + 1
  341.       end repeat
  342.       set currentFrame to getAt(frameList, relFrameCount)
  343.       add(currentFrame, [#tempo, fps])
  344.       setAt(frameList, relFrameCount, currentFrame)
  345.       repeat with animFrame = 1 to nAnimationFrames
  346.         set currentFrame to getAt(frameList, relFrameCount)
  347.         repeat with thisBullet = 1 to nSourceLines
  348.           set chItem to getAt(chList, thisBullet)
  349.           set castNumItem to getAt(bulletsList, thisBullet)
  350.           set locVItem to getAt(locVList, thisBullet)
  351.           set locHItem to getAt(locHList, thisBullet)
  352.           add(currentFrame, [#sprite, chItem, castNumItem, theForeColor, theBackColor, locHItem, locVItem, 0, 0])
  353.           if locHItem > leftEdge then
  354.             set thisH to integer(locHItem + hInc)
  355.             if thisH < leftEdge then
  356.               set thisH to leftEdge
  357.             end if
  358.             setAt(locHList, thisBullet, thisH)
  359.           end if
  360.         end repeat
  361.         setAt(frameList, relFrameCount, currentFrame)
  362.         set relFrameCount to relFrameCount + 1
  363.         set theFrameNum to theFrameNum + 1
  364.       end repeat
  365.       set currentFrame to getAt(frameList, relFrameCount)
  366.       add(currentFrame, [#tempo, -delayHold])
  367.       repeat with thisItem = 1 to nSourceLines
  368.         set chItem to getAt(chList, thisItem)
  369.         set castNumItem to getAt(bulletsList, thisItem)
  370.         set locVItem to getAt(locVList, thisItem)
  371.         add(currentFrame, [#sprite, chItem, castNumItem, theForeColor, theBackColor, leftEdge, locVItem, 0, 0])
  372.       end repeat
  373.       setAt(frameList, relFrameCount, currentFrame)
  374.       set theFrameNum to theFrameNum + 1
  375.       set relFrameCount to relFrameCount + 1
  376.     end if
  377.   end if
  378.   mWriteFrame(goScoreMgr, frameList)
  379.   set labelName to "Bullets" & goPlatform
  380.   go(label(labelName) + 2)
  381.   if not gDevelopmentFlag then
  382.     tell the stage
  383.       go(theStageFrame)
  384.     end tell
  385.   end if
  386.   mClean(goScoreMgr)
  387. end
  388.  
  389. on mCleanUp me
  390.   global goMotionStyles, goAnimateTitle, goSeconds, goFPS, goDelayEnter, goDelayHold, goMarkFrame
  391.   mCleanUp(goMotionStyles)
  392.   set iSaveSeconds to mGetValue(goSeconds)
  393.   set iSaveFPS to mGetValue(goFPS)
  394.   set iSaveDelayEnter to mGetValue(goDelayEnter)
  395.   set iSaveDelayHold to mGetValue(goDelayHold)
  396.   set iSaveMark to mGetValue(goMarkFrame)
  397.   set iSaveAnimateTitle to mGetValue(goAnimateTitle)
  398.   mCleanUp(goMarkFrame)
  399.   mCleanUp(goAnimateTitle)
  400. end
  401.